# coding:utf-8

from PyQt5 import QtCore, QtGui, QtWidgets
import sys
import qtawesome
from PyQt5.QtGui import QIcon


class MainUi(QtWidgets.QMainWindow):
    def __init__(self):
        super(MainUi, self).__init__()
        self.resize(960, 700)
        self.setWindowTitle("大数据抽样压缩工具")
        self.setWindowIcon(QIcon("../icon/sample256.ico"))

        # 创建窗口主部件
        self.main_widget = QtWidgets.QWidget()
        self.main_widget.setObjectName("main_widget")
        # 创建主部件的网格布局
        self.main_layout = QtWidgets.QGridLayout()
        # 设置窗口主部件布局为网格布局
        self.main_widget.setLayout(self.main_layout)

        # 创建左侧部件
        self.left_widget = QtWidgets.QWidget()
        self.left_widget.setObjectName('left_widget')
        # 创建左侧部件的网格布局层
        self.left_layout = QtWidgets.QGridLayout()
        # 设置左侧部件布局为网格
        self.left_widget.setLayout(self.left_layout)
        self.left_layout.setAlignment(QtCore.Qt.AlignTop)

        # 创建右侧部件
        self.right_widget = QtWidgets.QWidget()
        self.right_widget.setObjectName('right_widget')
        self.right_layout = QtWidgets.QGridLayout()
        self.right_widget.setLayout(self.right_layout)

        # 创建底部部件
        self.bottom_widget = QtWidgets.QWidget()
        self.bottom_widget.setObjectName("bottom_widget")
        self.bottom_layout = QtWidgets.QGridLayout()
        self.bottom_widget.setLayout(self.bottom_layout)

        # 左侧部件left_widget，8行3列
        self.main_layout.addWidget(self.left_widget, 0, 0, 8, 3)
        # 右侧部件right_widget，8行10列
        self.main_layout.addWidget(self.right_widget, 0, 3, 8, 10)
        # 底部部件bottom_widget，5行13列
        self.main_layout.addWidget(self.bottom_widget, 8, 0, 5, 13)
        # 设置窗口主部件
        self.setCentralWidget(self.main_widget)

        # 设置左侧窗口标签
        self.left_lb1 = QtWidgets.QLabel("配置文件")
        self.left_lb1.setObjectName("left_lb")
        self.left_lb2 = QtWidgets.QLabel("抽样")
        self.left_lb2.setObjectName("left_lb")
        self.left_lb3 = QtWidgets.QLabel("保存")
        self.left_lb3.setObjectName("left_lb")

        self.btn_data = QtWidgets.QPushButton(qtawesome.icon("fa.folder-open"), "数据集文件")
        self.btn_data.setObjectName("left_btn")
        self.btn_node = QtWidgets.QPushButton(qtawesome.icon("fa.folder-open"), "结点取值文件")
        self.btn_node.setObjectName("left_btn")
        self.btn_parent = QtWidgets.QPushButton(qtawesome.icon("fa.folder-open"), "父结点文件")
        self.btn_parent.setObjectName("left_btn")
        self.btn_sample = QtWidgets.QPushButton(qtawesome.icon("fa.play"), "抽样")
        self.btn_sample.setObjectName("left_btn")
        self.btn_save = QtWidgets.QPushButton(qtawesome.icon("fa.save"), "保存结果")
        self.btn_save.setObjectName("left_btn")
        self.btn_change = QtWidgets.QPushButton(qtawesome.icon("fa.exchange"), "转换形式")
        self.btn_change.setObjectName("left_btn")
        self.btn_save.setDisabled(1)
        self.btn_change.setDisabled(1)
        # 左侧布局添加部件
        self.left_layout.addWidget(self.left_lb1, 0, 0, 1, 1)
        self.left_layout.addWidget(self.btn_data, 1, 0, 1, 3)
        self.left_layout.addWidget(self.btn_node, 2, 0, 1, 3)
        self.left_layout.addWidget(self.btn_parent, 3, 0, 1, 3)
        self.left_layout.addWidget(self.left_lb2, 4, 0, 1, 1)
        self.left_layout.addWidget(self.btn_sample, 5, 0, 1, 3)
        self.left_layout.addWidget(self.left_lb3, 6, 0, 1, 1)
        self.left_layout.addWidget(self.btn_change, 7, 0, 1, 3)
        self.left_layout.addWidget(self.btn_save, 8, 0, 1, 3)

        # 设置左侧部件的样式表
        self.left_widget.setStyleSheet('''
            QWidget{
                color:#232C51;
                background:white;
                border-right:1px solid darkGray;
                border-top-left-radius:10px;
            }
            QLabel{
                color:#7f8c8d;
                border:none;
            }
            QPushButton{
                color:black;
                text-align:left;
                border:none;
                }
            QPushButton:hover{
                color:#FFFFFF;
                border-radius:5px;
                background-color: #1890FF;
            }
            QPushButton:pressed{
                color:#FFFFFF;
                border-radius:5px;
                background-color: #1890FF;
            }
        ''')

        self.right_lb1 = QtWidgets.QLabel("采样算法日志")
        self.right_lb1.setObjectName("right_lb")
        self.right_layout.addWidget(self.right_lb1, 0, 0, 1, 10)
        self.tb_conf = QtWidgets.QTextBrowser()
        self.tb_conf.setLineWrapMode(0)
        self.setObjectName("tb_conf")
        self.right_layout.addWidget(self.tb_conf, 1, 0, 7, 10)

        self.bottom_lb1 = QtWidgets.QLabel("采样算法结果（抽取出的样本在原样本的编号）")
        self.bottom_lb1.setObjectName("bottom_lb")
        self.bottom_layout.addWidget(self.bottom_lb1, 0, 0, 1, 13)
        self.tb_log = QtWidgets.QTextBrowser()
        self.tb_log.setLineWrapMode(0)
        self.setObjectName("tb_log")
        self.bottom_layout.addWidget(self.tb_log, 1, 0, 4, 13)

        vertical_scroll_style = '''
            QScrollBar:vertical{
                width:8px;
                background:transparent;
                margin:0px,0px,0px,0px;
                padding-top:0px;
                padding-bottom:0px;
            }
            QScrollBar::handle:vertical{
                width:8px;
                background:rgba(0,0,0,50%);
                border-radius:4px;
                min-height:80
            }
            QScrollBar::handle:vertical:hover{
                width:8px;
                background:rgba(0,0,0,70%);
                border-radius:4px;
                min-height:80;
            }
            /*
             接下来是为了取消两个翻页按钮，border-image里的图像不存在，其就是为了取消按钮
            */
            QScrollBar::add-line:vertical{
                height:0px;width:8px;
                border-image:url(:/images/null/null.png);
                subcontrol-position:bottom;
            }
            QScrollBar::sub-line:vertical{
                height:0px;width:8px;
                border-image:url(:/images/null/null.png);
                subcontrol-position:top;
            }
            QScrollBar::add-page:vertical,QScrollBar::sub-page:vertical{
                background:transparent;
                border-radius:4px;
            }
        '''

        horizontal_scroll_style = '''
            QScrollBar:horizontal{
                height:8px;
                background:transparent;
                margin:0px,0px,0px,0px;
                padding-left:0px;
                padding-right:0px;
            }
            QScrollBar::handle:horizontal{
                height:8px;
                background:rgba(0,0,0,50%);
                border-radius:4px;
                min-width:80;
            }
            QScrollBar::handle:horizontal:hover{
                height:8px;
                background:rgba(0,0,0,70%);
                border-radius:4px;
                min-width:80;
            }
            QScrollBar::add-line:horizontal{
                width:0px;
                height:8px;
                border-image:url(:/images/null/null.png);
                subcontrol-position:right;
            }
            QScrollBar::sub-line:horizontal{
                width:0px;
                height:8px;
                border-image:url(:/images/null/null.png);
                subcontrol-position:left;
            }
            QScrollBar::add-page:horizontal,QScrollBar::sub-page:horizontal{
                background:transparent;
                border-radius:4px;
            }
        '''

        self.tb_conf.horizontalScrollBar().setStyleSheet(horizontal_scroll_style)
        self.tb_conf.verticalScrollBar().setStyleSheet(vertical_scroll_style)
        self.tb_log.horizontalScrollBar().setStyleSheet(horizontal_scroll_style)
        self.tb_log.verticalScrollBar().setStyleSheet(vertical_scroll_style)

        right_style = '''
           QWidget{
                color:#232C51;
                background-color:white;
                border-top-right-radius:10px;
                
            } 
            QLabel{
                border:none;
                font-size:25px;
                font-weight:700;
                font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
            }
            QTextBrowser{
                border:none;
            }
        '''

        self.right_widget.setStyleSheet(right_style)

        bottom_style = '''
            QWidget{
                background-color:white;
            }
            QWidget#bottom_widget{
                color:#232C51;
                background-color:white;
                border-top:1px solid darkGray;
                border-bottom-right-radius:10px;
                border-bottom-left-radius:10px;
            }
            QLabel{
                border:none;
                font-size:25px;
                font-weight:700;
                font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
            }
            QTextBrowser{
                border:none;
            }
        '''

        self.bottom_widget.setStyleSheet(bottom_style)

        self.setWindowOpacity(0.95)
        self.main_layout.setSpacing(0)


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    gui = MainUi()
    gui.show()
    sys.exit(app.exec_())
